package com.tpix;

import java.io.IOException;
import java.util.List;

import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.tpix.photo.PhotoDAO;

public class HomeServlet extends HttpServlet implements Servlet {

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		//get the information from the request
		String action = request.getParameter("action");
		String albumName = request.getParameter("album");
		String keyID = request.getParameter("whichphoto");

		// get reference to core object
		PixieCore core = (PixieCore)request.getSession().getAttribute("core");
		if (core == null) {
			core = new PixieCore();
			request.getSession().setAttribute("core", core);
		}
		
		if (action.equals("Upload a Photo")) {
			response.sendRedirect("/upload.jsp");
		}
		else if (action.equals("Choose Album")) {
			core.setAlbum(albumName);
			request.getSession().setAttribute("core", core);

			response.sendRedirect("/home.jsp");
		}
		else if (action.equals("Photo Info")) {
			if (keyID == null || keyID.equals("")) {
				response.sendRedirect("/home.jsp");
			}
			else  {
				response.sendRedirect("/detail.jsp?kind=Photo&id=" + keyID);
			}

		}
	

	}

}